package org.sgx.gwtsjcltest.client;

import org.sgx.gwtsjcl.client.SJCL;
import org.sgx.gwtsjcl.client.SJCLLoader;

import com.google.gwt.core.client.Callback;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;

public class GWTSJCLEmbeddedTestEntryPoint implements EntryPoint {

	@Override
	public void onModuleLoad() {
		
		System.out.println("GWTSJCLEmbeddedTestEntryPoint");
		
		String password = "banana4", 
				plainText = "En algún lugar de la mancha - embedded";
		SJCL sjcl = SJCL.sjcl();
		String encrypted = sjcl.encrypt(password, plainText);
		String decrypted = sjcl.decrypt(password, encrypted);
		System.out.println(encrypted + " - " + decrypted);
		
		
//		 testEmbedded();
//		testNotEmbedded();
	}

//	private void testEmbedded() {
//		String password = "banana4", 
//				plainText = "En algún lugar de la mancha - embedded";
//		SJCL sjcl = SJCL.sjcl();
//		String encrypted = sjcl.encrypt(password, plainText);
//		String decrypted = sjcl.decrypt(password, encrypted);
//		System.out.println(encrypted + " - " + decrypted);
//	}
//
//	private void testNotEmbedded() {
//		String scriptUrl = "http://crypto.stanford.edu/sjcl/sjcl.js";
//		SJCLLoader.load(scriptUrl, new Callback<Void, Exception>() {
//			@Override
//			public void onSuccess(Void result) {
//				// ready to work
//				String password = "banana4", 
//						plainText = "En algún lugar de la mancha not embedded";
//				SJCL sjcl = SJCL.sjcl();
//				String encrypted = sjcl.encrypt(password, plainText);
//				String decrypted = sjcl.decrypt(password, encrypted);
//				System.out.println(encrypted + " - " + decrypted);
//			}
//
//			@Override
//			public void onFailure(Exception reason) {
//				Window.alert("Couldn't load SJCL Library from http://crypto.stanford.edu/sjcl/");
//			}
//		});
//	}

}
